<?php
// +----------------------------------------------------------------------
// | 幕小铺
// +----------------------------------------------------------------------
// | 版权所有 2016~2020 幕小铺科技（大连）有限公司
// +----------------------------------------------------------------------
// | 2020/03/14
// +----------------------------------------------------------------------

namespace app\erp\model;

use think\Model;

/**
 * 预设规格属性
 * @package app\erp\model
 */
class ErpSpecificationsAttribute extends Model
{
    // 设置当前模型对应的完整数据表名称
    protected $table = 'xm_erp_specifications_attribute';
	
    /**
     * 添加数据
     * @param title 	string 属性名称
     * @param sid 		int    规格id
     * @param sort 		int    排序
     * @author shiqiang
     * @return array_out(code, message, (int)id)
     */
    public function addData($title, $sort, $sid){
        $data['title']        = $title;
        $data['sid']      	  = $sid;
        $data['sort']         = $sort;
        $res = $this -> isUpdate(false) ->data($data, true) -> save();
        if($res){
            return array_out(200, 'success');
        }else{
            return array_out(-1001, 'error');
        }
    }
	
	
	/**
     * 编辑数据
     * @param id 		int id
     * @param title 	string 店铺名称
     * @param address 	string 地址
     * @param sort 		int    排序
     * @param code 		string 门店编码
     * @author shiqiang
     * @return array_out(code, message, (int)id)
     */
	public function editData($id, $title, $sort){
		$map = [];
		$map['id'] = $id;
		
		$data = [];
		$data['title'] 		= $title;
		$data['sort'] 		= $sort;
		$res = $this ->update($data, $map);
		if($res){
            return array_out(200, 'success');
        }else{
            return array_out(-1001, 'error');
        }
	}
	
	/**
     * 删除数据
     * @param int $id
     * @author shiqiang <976162041@qq.com>
     * @return bool
     */
    public function deleteData($id){
        $res = self::destroy($id);
        if($res){
            return array_out(200, 'success');
        }else{
            return array_out(-1001, 'error');
        }
    }
}
